$(function(){
	$('.mc').css('display','none');
	$('#categorys').hover(function(){
		$(this).children('.mc').toggle();
	});
	$Base.isLogin(location.href, getFavList);
});

function getFavList() {
	var url = '/json?action=QUERY_T_PRODUCT_FAVORITESBY_PAGER_ACTION';
	var pageSize = 10;
	var defaultHtml = '<tr><td colspan="3">您还没有收藏任何商品...</td></tr>';
	var current = $Util.getQueryString(document.location.search,'current');
	$UI.changePage(url,pageSize,'T_PRODUCT_FAVORITES','#fav_list',printFav,'#pager',defaultHtml,current,'#topPagePanel');
}

function printFav(obj,result,i,n,len,c,t) {
	if (t) {
		$('#totalProducts').html('共<strong>'+t+'</strong>个商品');
		$('#pageShow').html(c+'/'+(Math.floor(t/25)+1));
	}
	var div = [
		'<tr>',
			'<td width="50%" style="padding-left:20px;">',
			'<div class="fl"><a href="../product/file.html?id='+obj.PRODUCT_ID+'" target="blank"><img src="../upload/product/'+obj.PRODUCT_NO+'.jpg" width="50" height="50" style="border:1px solid #E9E9E9;"/></a></div>',
			'<div class="fl">&nbsp;&nbsp;<a href="../product/file.html?id='+obj.PRODUCT_ID+'"  target="blank">',obj.PRODUCT_NAME,'</a></div></td>',
			'<td width="30%">',$Util.toChar(obj.FAVORITES_DATE,'yyyy-mm-dd'),'</td>',
			'<td width="20%"><a href="#" class="blue" onclick="deleteFav('+obj.PRODUCT_FAVORITES_ID+')">删除</a></td>',
		'</tr>'
	].join('');		
	$(result).append(div);
}

function deleteFav(id) {
	var url = '/json?action=DELETE_T_PRODUCT_FAVORITES_ACTION&FAV_ID='+id;
	$.post(url,{},function(data){
		if(data.success){
			getFavList();
		} else {
			alert("删除失败");
		}
	},'json');
}
